package main.Q1701_1800;

import java.util.*;

public class Q1741_1750 {
	public static void main(String[] args) {
		System.out.println("Question1741：");
		System.out.println("Question1742：");
		System.out.println("Question1743：从相邻元素对还原数组");
		System.out.println("Question1744：");
		System.out.println("Question1745：");
		System.out.println("Question1746：");
		System.out.println("Question1747：");
		System.out.println("Question1748：唯一元素的和");
		System.out.println("Question1749：");
		System.out.println("Question1750：");
	}
}

class Question1743{
	public int[] restoreArray(int[][] adjacentPairs) {
		int m = adjacentPairs.length, n = m + 1;
		Map<Integer, Integer> counts = new HashMap<>();
		Map<Integer, List<Integer>> map = new HashMap<>();
		for (int[] ap : adjacentPairs) {
			int a = ap[0], b = ap[1];
			counts.put(a, counts.getOrDefault(a, 0) + 1);
			counts.put(b, counts.getOrDefault(b, 0) + 1);
			List<Integer> alist = map.getOrDefault(a, new ArrayList<>());
			alist.add(b);
			map.put(a, alist);
			List<Integer> blist = map.getOrDefault(b, new ArrayList<>());
			blist.add(a);
			map.put(b, blist);
		}
		int start = -1;
		for (int i : counts.keySet()) {//寻找边界元素
			if (counts.get(i) == 1) {
				start = i;
				break;
			}
		}
		int[] result = new int[n];//单向构造
		result[0] = start;
		result[1] = map.get(start).get(0);
		for (int i = 2; i < n; i++) {
			int x = result[i - 1];
			List<Integer> list = map.get(x);
			for (int j : list) {
				if (j != result[i - 2]) result[i] = j;
			}
		}
		return result;
	}
}

class Question1748{
	public int sumOfUnique(int[] nums) {
		int sum=0;
		Map<Integer,Integer> map=new HashMap<>();
		for (int num:nums) {
			map.put(num,map.getOrDefault(num,0)+1);
		}
		for (int num:map.keySet()) {
			if (map.get(num)==1) {
				sum+=num;
			}
		}
		return sum;
	}
}